package cn.achao.csr.base.exception.handler;

import cn.achao.csr.base.exception.BusinessException;
import cn.achao.csr.base.exception.InnerAuthException;
import cn.achao.csr.base.resp.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @Author: achao
 **/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R<?> handleException(Exception e) {
        log.error("全局异常处理 Exception 异常", e);
        return R.fail("服务异常");
    }

    @ExceptionHandler(BusinessException.class)
    public R<?> handleBusinessException(BusinessException e) {
        log.error("全局异常处理 BusinessException 异常", e);
        return R.fail(e.getDescription());
    }

    @ExceptionHandler(InnerAuthException.class)
    public R<?> handleInnerAuthException(InnerAuthException e) {
        log.error("全局异常处理 InnerAuthException 异常", e);
        return R.fail(e.getMessage());
    }
}
